//
//  TGCategoryMenuItem.m
//  GroupBuy
//
//  Created by wwj on 15/11/4.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "TGCategoryMenuItem.h"
#import "TGCategoryModel.h"

#define kTitleRatio 0.5

@implementation TGCategoryMenuItem
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.imageView.contentMode = UIViewContentModeCenter;
    }
    return self;
}

-(NSArray *)titleArray{
    return _model.subcategories;
}

-(void)setModel:(TGCategoryModel *)model{
    _model = model;
    [self setImage:[UIImage imageNamed:model.icon] forState:UIControlStateNormal];
    [self setTitle:model.name forState:UIControlStateNormal];
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat H = contentRect.size.height * kTitleRatio;
    CGFloat W = contentRect.size.width;
    return CGRectMake(0, contentRect.size.height-H, W, H);
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat H = contentRect.size.height * (1-kTitleRatio);
    CGFloat W = contentRect.size.width;
    return CGRectMake(0, 4, W, H);
}
@end
